package cn.hgpu.servlet;

import cn.hgpu.mapper.RoleMapper;
import cn.hgpu.utils.MybatisUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/role/delete")
public class RoleDeleteById extends HttpServlet {
    private RoleMapper roleMapper = MybatisUtils.getMapper(RoleMapper.class);
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取参数
        String id = req.getParameter("id");

        //逻辑处理
        roleMapper.deleteById(Integer.parseInt(id));
        MybatisUtils.commit();

        ////修改成功，跳转到查询servlet,经过其跳转到首页
        resp.sendRedirect("/role/list");
    }
}
